import com.gmongo.GMongo
import com.mongodb.DBRef

includeTargets << grailsScript("_GrailsInit")
includeTargets << grailsScript("_GrailsBootstrap")

target(main: "Create a test user and testcase") {
    depends bootstrap

    def db = new GMongo().getDB(grailsApp.config.grails.mongo.databaseName)
    //def db = new GMongo("ec2-184-169-249-64.us-west-1.compute.amazonaws.com", 27017).getDB(grailsApp.config.grails.mongo.databaseName)
    def currentDate = new Date()
    db.user << [username: 'testuser', password: 'testuser'.encodeAsMD5(), dateCreated: currentDate, lastUpdated: currentDate]
    def user = db.user.findOne(username: 'testuser')

    def testScript = '''\
package simtester.agent
import geb.*
import java.util.logging.*
class AgentScript {
  static runtest() {
    def log = Logger.getLogger("simtester.agent")
    Browser.drive {
      go 'http://www.google.com'
      log.info("Title: $title")
      assert 'Google' == title
    }
  }
}'''

    currentDate = new Date()
    db.testCase << [name: 'DefaultGoogleTest', owner: new DBRef(null, 'user', user._id), script: testScript, dateCreated: currentDate, lastUpdated: currentDate]
}

setDefaultTarget(main)
